<?php

/*
	info: 后台登录模块
	date: 11-01-12
*/

if (!defined('ADMIN_WEBINROOT'))
{
	header("HTTP/1.0 404 Not Found");
	exit();
}

$webglobal['adminremurl'] = FALSE;

if ($webglobal['mode']=='exit')
{
	global_ClearCookie($webglobal['admincookie']);
	global_ClearCookie('adminlasturl');
	admin_ShowMessage('您已成功退出管理中心。', ADMIN_WEBURLPATH.'/index.php?mode=login');
}

$webglobal['errmsg'] = '';
if (global_CheckSubmit('loginsubmit'))
{
	if ($webrequest['username']=='' || $webrequest['password']=='')
	{
		$webglobal['errmsg'] = '用户名或者密码不能为空';
	}
	elseif (!global_CheckUsername($webrequest['username']))
	{
		$webglobal['errmsg'] = '用户名格式错误';
	}
	else
	{
		$webglobal['errmsg'] = '用户名或者密码错误';
		$query = $db->Query("SELECT * FROM {$webconfig['dbpre']}admin_user WHERE username='{$webrequest['username']}'");
		if ($tempinfo = $db->FetchArray($query))
		{
			if ($tempinfo['password']==admin_EncodePassword($webrequest['password']))
			{
				$user['adminuid'] = $tempinfo['id'];
				$user['adminusername'] = $tempinfo['username'];
				$user['adminpassword'] = $tempinfo['password'];
				global_SetCookie($webglobal['admincookie'], global_EncryptKey($user['adminuid']."\t".$user['adminusername']."\t".$user['adminpassword'], ADMIN_WEBAUTHKEY));
				admin_AddLog('登录系统');
				admin_ShowMessage("{$user['adminusername']} 欢迎您登录徳力电子商务管理系统，系统载入中...", ADMIN_WEBURLPATH.'/index.php?mode=index');
			}
		}
		unset($tempinfo);
	}
}

template_Display('login', 1);

?>